﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Layout_2 : MonoBehaviour
{
    public Key_2[] keys;
    public SliderChange_2[] sliders;
    // Start is called before the first frame update
    void Awake()
    {
        keys = this.GetComponentsInChildren<Key_2>();
        sliders = this.GetComponentsInChildren<SliderChange_2>();
    }

    public void SetKeyMusic()
    {
        for (int i = 0; i < keys.Length; i++)
        {
            string name = keys[i].gameObject.name;
            if(keys[i].isAuto==true)
            {
                AudioClip[] temp = new AudioClip[7];

                switch (name)
                {
                    case "w1":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 0];
                        break;
                    case "w2":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 1];
                        break;
                    case "w3":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 2];
                        break;
                    case "w4":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 3];
                        break;
                    case "w5":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 4];
                        break;
                    case "w6":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 5];
                        break;
                    case "w7":
                        for (int j = 0; j < 7; j++)
                            temp[j] = GameData.whiteSounds[j, 6];
                        break;
                    default:
                        break;
                }
                keys[i].SetClip(temp);
            }
            else
            {
                AudioClip temp = null;

                switch (name)
                {
                    case "w1":
                        temp = GameData.whiteSounds[2, 0];
                        break;
                    case "w2":
                        temp = GameData.whiteSounds[2, 1];
                        break;
                    case "w3":
                        temp = GameData.whiteSounds[2, 2];
                        break;
                    case "w4":
                        temp = GameData.whiteSounds[2, 3];
                        break;
                    case "w5":
                        temp = GameData.whiteSounds[2, 4];
                        break;
                    case "w6":
                        temp = GameData.whiteSounds[2, 5];
                        break;
                    case "w7":
                        temp = GameData.whiteSounds[2, 6];
                        break;
                    case "w1 (1)":
                        temp = GameData.whiteSounds[3, 0];
                        break;
                    case "w2 (1)":
                        temp = GameData.whiteSounds[3, 1];
                        break;
                    case "w3 (1)":
                        temp = GameData.whiteSounds[3, 2];
                        break;
                    case "w4 (1)":
                        temp = GameData.whiteSounds[3, 3];
                        break;
                    case "w5 (1)":
                        temp = GameData.whiteSounds[3, 4];
                        break;
                    case "w6 (1)":
                        temp = GameData.whiteSounds[3, 5];
                        break;
                    case "w7 (1)":
                        temp = GameData.whiteSounds[3, 6];
                        break;
                    case "w1 (2)":
                        temp = GameData.whiteSounds[4, 0];
                        break;
                    case "w2 (2)":
                        temp = GameData.whiteSounds[4, 1];
                        break;
                    case "w3 (2)":
                        temp = GameData.whiteSounds[4, 2];
                        break;
                    case "w4 (2)":
                        temp = GameData.whiteSounds[4, 3];
                        break;
                    case "w5 (2)":
                        temp = GameData.whiteSounds[4, 4];
                        break;
                    case "w6 (2)":
                        temp = GameData.whiteSounds[4, 5];
                        break;
                    case "w7 (2)":
                        temp = GameData.whiteSounds[4, 6];
                        break;
                    default:
                        temp = GameData.whiteSounds[2, 0];
                        break;
                }

                keys[i].SetClip(temp);
            }
        }

    }
    public void SetCustom()
    {
        for (int i = 0; i < keys.Length; i++)
        {
            string name = keys[i].gameObject.name;
            int index = 0;
            Vector3 postion;
            Vector3 size;
            switch (name)
            {
                case "w1":
                    index = 0;
                    break;
                case "w2":
                    index = 1;
                    break;
                case "w3":
                    index = 2;
                    break;
                case "w4":
                    index = 3;
                    break;
                case "w5":
                    index = 4;
                    break;
                case "w6":
                    index = 5;
                    break;
                case "w7":
                    index = 6;
                    break;
                default:
                    break;
            }
            postion = new Vector3(GameData.keyDatas[index].x, GameData.keyDatas[index].y, 0);
            size = new Vector3(GameData.keyDatas[index].r, GameData.keyDatas[index].r, 1);

            keys[i].transform.localPosition = postion;
            keys[i].transform.localScale = size;
        }
    }
}
